cmake_minimum_required(VERSION 3.10)
project(mqtt_ota C)

# 设置C标准
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)

# 设置安装前缀
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
    set(CMAKE_INSTALL_PREFIX "/usr/local" CACHE PATH "Installation directory" FORCE)
endif()

# 添加子目录
add_subdirectory(src)

# 安装配置文件
install(
    FILES config/mqtt_ota.conf
    DESTINATION ${CMAKE_INSTALL_PREFIX}/etc/mqtt_ota
    PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
)

# 安装系统服务文件
if(UNIX AND NOT APPLE)
    install(
        FILES config/mqtt_ota.service
        DESTINATION /lib/systemd/system
        PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
    )
endif()

# 安装脚本
install(
    DIRECTORY scripts/
    DESTINATION ${CMAKE_INSTALL_PREFIX}/share/mqtt_ota/scripts
    USE_SOURCE_PERMISSIONS
)

# 打包目标
set(CPACK_PACKAGE_NAME "mqtt-ota-nanosdk")
set(CPACK_PACKAGE_VERSION "1.0.0")
set(CPACK_PACKAGE_DESCRIPTION "MQTT OTA Update Client using NanoSDK")
set(CPACK_PACKAGE_CONTACT "Your Name <your.email@example.com>")
include(CPack)
